/*
 * @Description: 
 * @Author: mxy
 * @Date: 2022-11-21 21:05:52
 * @LastEditors: mxy
 * @LastEditTime: 2022-11-21 21:14:22
 */
const { join } = require('path')
const file = join(__dirname, 'books.json')
const { readFile, writeFile } = require('fs')

readFile(file, 'utf-8', (err, data) => {
    if (err) throw err
    const arr = JSON.parse(data)
    arr.push({
        "id": arr[arr.length - 1].id + 1,
        "bookname": "三国演义",
        "author": "唐僧",
        "publisher": "北京出版社"
    })
    writeFile(file, JSON.stringify(arr), err => {
        if (err) throw err
        console.log('添加成功');
    })

})